package net.zjitc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.zjitc.mapper.NoticeMapper;
import net.zjitc.pojo.Notice;
import net.zjitc.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @Author admin
 * @DATE 2019/3/28 14:56
 */
@Service
@Transactional
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    NoticeMapper noticeMapper;

    @Override
    public int addNotice(Notice notice) {
        notice.setN_time(new Date());
        return noticeMapper.addNotice(notice);
    }

    @Override
    public List<Notice> findAll() {
        return noticeMapper.findAll();
    }

    @Override
    public Notice findById(int id) {
        return noticeMapper.findById(id);
    }

    @Override
    public int editNotice(Notice notice) {
        return noticeMapper.editNotice(notice);
    }

    @Override
    public int deleteNotice(int id) {
        return noticeMapper.deleteNotice(id);
    }

    @Override
    public PageInfo<Notice> findNoticeByPage(Integer currentPage, Integer pageSize){
        if (pageSize == null){
            pageSize = 3;
        }
        PageHelper.startPage(currentPage,pageSize);
        List<Notice> list = noticeMapper.findAll();
        return new PageInfo<Notice>(list);
    }

    @Override
    public Notice details() {
        return noticeMapper.details();
    }
}
